package com.ruoyi.xyh.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.xyh.domain.NewsRele;
import com.ruoyi.xyh.service.INewsReleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 新闻发布Controller
 * 
 * @author ruoyi
 * @date 2024-03-26
 */
@RestController
@RequestMapping("/xyh/newsRele")
public class NewsReleController extends BaseController
{
    @Autowired
    private INewsReleService newsReleService;

    /**
     * 查询新闻发布列表
     */
    @PreAuthorize("@ss.hasPermi('xyh:newsRele:list')")
    @GetMapping("/list")
    public TableDataInfo list(NewsRele newsRele)
    {
        startPage();
        List<NewsRele> list = newsReleService.selectNewsReleList(newsRele);
        return getDataTable(list);
    }

    /**
     * 导出新闻发布列表
     */
    @PreAuthorize("@ss.hasPermi('xyh:newsRele:export')")
    @Log(title = "新闻发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NewsRele newsRele)
    {
        List<NewsRele> list = newsReleService.selectNewsReleList(newsRele);
        ExcelUtil<NewsRele> util = new ExcelUtil<NewsRele>(NewsRele.class);
        util.exportExcel(response, list, "新闻发布数据");
    }

    /**
     * 获取新闻发布详细信息
     */
    @PreAuthorize("@ss.hasPermi('xyh:newsRele:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(newsReleService.selectNewsReleById(id));
    }

    /**
     * 新增新闻发布
     */
    @PreAuthorize("@ss.hasPermi('xyh:newsRele:add')")
    @Log(title = "新闻发布", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NewsRele newsRele)
    {
        return toAjax(newsReleService.insertNewsRele(newsRele));
    }

    /**
     * 修改新闻发布
     */
    @PreAuthorize("@ss.hasPermi('xyh:newsRele:edit')")
    @Log(title = "新闻发布", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NewsRele newsRele)
    {
        return toAjax(newsReleService.updateNewsRele(newsRele));
    }

    /**
     * 删除新闻发布
     */
    @PreAuthorize("@ss.hasPermi('xyh:newsRele:remove')")
    @Log(title = "新闻发布", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(newsReleService.deleteNewsReleByIds(ids));
    }
}
